package api;

import utils.CommUtils;
import utils.HttpUtils;

import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

/**
 * OCR API接口
 */
public class OcrApi extends AccessToken {
    private final static String ocrURI = "/aip/ocr/v1/rec/idcard";


    /**
     * 1.身份证OCR识别
     */
    public static void ocrIdCard(String _BizNo, String imageBase64) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("imageBase64", imageBase64);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, ocrURI, getCachedAccessToken(), paramsMap);
        System.out.println("ocr识别接口-- >> ocrElem:" + res);
    }

    public static void main(String[] args) {

        String base64 = CommUtils.fileToBase64Str("C:\\Users\\admin\\Pictures\\img\\1.jpg");
        //1.身份证OCR识别接口
        ocrIdCard(UUID.randomUUID().toString(), base64);
    }

}
